package com.donquijote.spring14.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 421527548@qq.com
 * @version V1.0
 * @title
 * @description
 * @date 2022-11-29 20:17
 */
@Component
@Aspect
public class SecurityAspect {

    @Pointcut("execution(* com.donquijote.spring14..add*(..))")
    public void addPointcut(){}

    @Pointcut("execution(* com.donquijote.spring14..delete*(..))")
    public void deletePointcut(){}
    @Pointcut("execution(* com.donquijote.spring14..modify*(..))")
    public void modifyPointcut(){}
    @Pointcut("execution(* com.donquijote.spring14..get*(..))")
    public void getPointcut(){}

    @Before("addPointcut()||deletePointcut()||modifyPointcut()||getPointcut()")
    public void addAdvice(JoinPoint joinPoint){
        Signature signature = joinPoint.getSignature();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = dateFormat.format(new Date());
        System.out.println(format + " " + signature.getDeclaringType() + "." + signature.getName() );
    }
}
